<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearList"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        :label="$t('message.xfyh')"
        min-width="250"
        align="center"
        show-overflow-tooltip
        prop="memberInfo"
      />
      <el-table-column
        align="center"
        :label="$t('message.xflx')"
        min-width="200"
        prop="sourceName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.szlx')"
        min-width="100"
        prop="type"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == '1'">{{ $t('message.sr') }}</span>
          <span v-if="scope.row.type == '2'" class="secondColor">{{ $t('message.zhichu') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.scsrjf')"
        prop="integral"
        min-width="140"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == '1'">{{ scope.row.integral }}</span>
          <template v-if="scope.row.type == '2'">
            <span
              v-if="scope.row.integral > 0"
              class="secondColor"
            >- {{ scope.row.integral }}</span>
            <span v-else>{{ scope.row.integral }}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.sfye')"
        prop="memberIntegral"
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.zcsrsj')"
        prop="createTime"
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="$t('message.ddbh')"
        min-width="220"
        show-overflow-tooltip
        prop="orderId"
      />
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { integralDetail, consumptionType } from '@/api'
import { parseTime } from '@/utils/index'
import QueryForm from '@/components/QueryForm'
export default {
  name: 'Integraldetailed',
  components: {
    QueryForm
  },
  data() {
    return {
      list: [],
      queryFormConfig: {
        formItems: [{
          filed: 'orderId',
          type: 'input',
          label: this.$t('message.ddbh'),
          clearable: true
        }, {
          filed: 'memberInfo',
          type: 'input',
          label: this.$t('message.xfyh'),
          placeholder: this.$t('message.hy2'),
          clearable: true
        }, {
          filed: 'source',
          type: 'select',
          label: this.$t('message.xflx'),
          labelCode: 'value',
          valueCode: 'code',
          clearable: true,
          options: []
        }],
        online: true
      },
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      filters: {},
      listLoading: true
    }
  },
  created() {
    this.getConsumptionType()
    this.getList(1)
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    clearList() {
      this.filters = {}
      this.getList(1)
    },
    getConsumptionType() {
      consumptionType({ param: {}})
        .then((res) => {
          if (res.errorCode !== '000000') return
          this.queryFormConfig.formItems[2].options = res.recordList
        })
        .catch((err) => {
          console.log(err)
        })
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      filters.flag = '1'
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      integralDetail({ pagination, param: { venueId, ...filters }})
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.list = res.recordList
          this.total = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
